package com.example.blog.mapper;

import com.example.blog.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BlogInfoMapper {

    //返回博客列表
    @Select("select * from blog where delete_flag != 1")
    List<BlogInfo> selectAllBlog();

    //根据博客id返回博客信息
    @Select("select * from blog where id = #{id} and delete_flag != 1")
    BlogInfo selectBlogById(Integer id);

    //更新博客
    Integer updateBlog(BlogInfo blogInfo);

    //插入博客
    @Insert("insert into blog (title, content, user_id) " +
            "values (#{title}, #{content}, #{userId})")
    Integer insertBlog(BlogInfo blogInfo);

    //获取作者id
    @Select("select user_id from blog where id = #{blogId}")
    Integer selectUserIdByBlogId(Integer blogId);

    @Select("select * from blog where user_id = #{userId} and delete_flag != 1")
    List<BlogInfo> selectBlogByUserId(Integer userId);
}
